﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using TierApplication;

public partial class ForeProgram_shopMyUserInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
            Load();
        }
    }

    #region
    private void BindData()
    {
        T_ACCOUNT account = new T_ACCOUNT(Security.GetAccountId());
        lblAccountid.Text = account.ACCOUNTID;
        txtAccountName.Text = account.ACCOUNTNAME;
        txtBirthday.Text = account.BIRTHDAY.HasValue ? account.BIRTHDAY.Value.ToString("yyyy-MM-dd") : "";
        txtContac_addr.Text = account.CONTAC_ADDR;
        txtEmail.Text = account.EMAIL;
        txtMobile.Text = account.MOBILE;
        txtPostcode.Text = account.POSTCODE;
        dlSchool.SelectedValue = account.SCHOOLID;
        if (account.GENDER != "")
            rbtGender.SelectedValue = account.GENDER;
    }
    #endregion

    #region
    private void Load()
    {
        T_SCHOOL schol = new T_SCHOOL();
        dlSchool.DataSource = schol.GetList("");
        dlSchool.DataValueField = "schoolid";
        dlSchool.DataTextField = "schoolshortname";
        dlSchool.DataBind();
        dlSchool.Items.Insert(0, new ListItem("--请选择--", ""));
    }
    #endregion

    #region 提交
    /// <summary>
    /// 提交
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void imgSubit_Click(object sender, ImageClickEventArgs e)
    {
        T_ACCOUNT account = new T_ACCOUNT(Security.GetAccountId());
        account.ACCOUNTNAME = txtAccountName.Text;
        if (txtBirthday.Text != "")
            account.BIRTHDAY = Convert.ToDateTime(txtBirthday.Text);
        else
            account.BIRTHDAY = DateTime.MinValue;
        account.CONTAC_ADDR = txtContac_addr.Text;
        account.EMAIL = txtEmail.Text;
        account.MOBILE = txtMobile.Text;
        account.POSTCODE = txtPostcode.Text;
        if (rbtGender.SelectedIndex != -1)
            account.GENDER = rbtGender.SelectedValue;
        else
            account.GENDER = "";
        account.SCHOOLID = dlSchool.SelectedValue;
        if (account.Update())
        {
            Session["AccountInfo"] = account;
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), DateTime.Now.ToLongTimeString(), "<script>alert('保存成功！');</script>");
        }
        else
        {
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), DateTime.Now.ToLongTimeString(), "<script>alert('失败成功！');</script>");
        }

    }
    #endregion
}